<?php

use yii\helpers\Html;
use yii\grid\GridView;
use app\models\Auction;

/* @var $this yii\web\View */
/* @var $searchModel app\models\ProductSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title ='竞拍';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="product-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'auctionid',
            'product.name',
            'periods',
            [
                'attribute' => 'state',
                'value'=>function($model){
                    /* @var $model app\models\Product */
                    return Auction::dropdown('state',$model->state);
                },
                'filter'=>Auction::dropdown('state'),
                'filterInputOptions'=>['prompt'=>'全部','class'=>'form-control'],
                'headerOptions'=>['width'=>'10%'],
            ],
            [
                'attribute' => 'created_at',
                'format' => ['date', 'php:Y-m-d']
            ],
            [
                'attribute' => 'updated_at',
                'format' => ['date', 'php:Y-m-d']
            ],

            [
                'class' => 'yii\grid\ActionColumn',
                'template'=>'{view}{bid-rcd}{test}{start}{end}',
                'buttons'=>[
                    'bid-rcd' => function ($url, $model, $key) {
                        return Html::a('&nbsp;<span class="glyphicon glyphicon-bishop"></span>',
                            $url,
                            ['title' => '出价记录'] );
                    },
                    'test'=>function($url,$model,$key){
                        return Html::a('&nbsp;<span class="glyphicon glyphicon-bookmark"></span>',
                            $url,
                            ['title' => '测试'] );

                    },
                    'start'=>function($url,$model,$key){
                        return Html::a('&nbsp;<span class="glyphicon glyphicon-ok"></span>',
                            $url,
                            ['title' => '开始'] );
                    },
                    'end'=>function($url,$model,$key){

                        return Html::a('&nbsp;<span class="glyphicon glyphicon-remove"></span>',
                            $url,
                            ['title' => '结束'] );

                    }

                ],
                'visibleButtons'=>[
                    'start'=>function($model,$key,$index){
                        /* @var $model app\models\Auction */
                        return $model->state == Auction::STATE_READY;
                    },
                    'test'=>function($model,$key,$index){
                        /* @var $model app\models\Auction */
                        return $model->state == Auction::STATE_IS_AUCTION;
                    },
                    'end'=>function($model,$key,$index){
                        /* @var $model app\models\Auction */
                        return $model->state == Auction::STATE_IS_AUCTION;
                    }

                ]
            ],
        ],
    ]); ?>
</div>
